from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from configuration.config import DB_URI_PYMYSQL

Base = declarative_base()
engine = create_engine(DB_URI_PYMYSQL)

class hit_doc_history(Base):
    __tablename__ = 'hit_doc_history'  # 数据库中已存在名为 hit_doc_history 的表
    __table_args__ = {'autoload_with': engine, 'extend_existing': True}  # 使用 engine 来自动加载表结构

    #id = Column(Integer, primary_key=True)
    chat_child_id = Column(Integer)
    source = Column(String)
    page_content = Column(String)
    doc_id = Column(String)
    del_flag = Column(Integer)
    url = Column(String)
    page = Column(String)

    def __repr__(self):
        return "{'chat_child_id':'%s', 'source':'%s', 'page_content':'%s','doc_id':'%s','del_flag':'%s','url':'%s','page':'%s'}" % (
            self.chat_child_id, self.source, self.page_content,self.doc_id,self.del_flag,self.url,self.page)

    def to_dict(self):
        return {
            "chat_child_id": self.chat_child_id,
            "source": self.source,
            "page_content": self.page_content,
            "doc_id":self.doc_id,
            "del_flag": self.del_flag,
            "url": self.url,
            "page":self.page
        }